# -*- coding:utf-8 -*-
import platform
import os
import shutil
import sys
import time
import math
import json
import zipfile


sys.path.append("..")
sys.path.append("../Utils")



import FileUtils
import MapUtils


#主要是计算md5差异
class DiffMD5Helper:
    def __init__(self,targetVersionStr):
        self.targetVersionStr = targetVersionStr
        pass

    # md5FileDirPath 放版本md5文件的文件夹路径
    def diffVersionFile(self,versionList,md5FileDirPath):
        myPath = os.path.join(md5FileDirPath,self.targetVersionStr + ".json")
        myMD5Map = FileUtils.getJsonFileData(myPath)

        _map = {}

        def diffFunc(map1,map2,key):
            print("key = " + key)
            if map1.get(key):
                if map2.get(key):
                    if(map1[key]['md5'] == map2[key]["md5"]):
                        print("#### 1 相等")
                        pass
                    else:
                        print("#### 2 不相等")
                        return map1[key]
                else:
                    #新版本把这个文件删除了
                    print(">>>>>>>>> 新版本有,旧版本没有")
                    return map1[key]
            else:
                if map2.get(key):
                    print(">>>>> 新版本没有,旧版本有")
                    pass
                else:
                    print(">>>>> 新增")
                    #新版本有,旧版本没有
                    return map1.get(key)


        for versionStr in versionList:
            if versionStr == self.targetVersionStr:
                continue
            path = os.path.join(md5FileDirPath,versionStr + ".json")
            otherMD5Map = FileUtils.getJsonFileData(path)
            # print(">>>>>>>>  ",self.targetVersionStr,versionStr)
            _diffMap = MapUtils.diffMap(myMD5Map,otherMD5Map,diffFunc)
            # print(">>>>>>>>  _diffMap = ",_diffMap)
            _map[versionStr] = _diffMap
        pass

        return _map





